<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <meta name="csrf_token" id="token" content="{{ csrf_token() }}">
    @include('public.h5_head')
    <title>订单详情</title>
    <script src="{{ env('CDN_DOMAIN_NAME') }}/js/commonjs/rem.js"></script>
    <link href="{{env('CDN_DOMAIN_NAME')}}/css/font-awesome.min.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="{{ env('CDN_DOMAIN_NAME') }}/css/commoncss/common.css"/>
    <link rel="stylesheet" type="text/css" href="{{ env('CDN_DOMAIN_NAME') }}/css/exchange_order_details.css"/>
    <link rel="stylesheet" type="text/css" href="{{ env('CDN_DOMAIN_NAME') }}/store/css/cart.css?v=1.3.0"/>
    <script src="{{ env('CDN_DOMAIN_NAME') }}/js/app.js"></script>
    <script src="{{ env('CDN_DOMAIN_NAME') }}/js/commonjs/4.2.5iscroll.js"></script>
</head>
<body>
<div id="box_cart">
    <div class="wrap" id="#wrapper">
        <div class="cart">
            <span class="owns sp"><b>收件人信息</b></span>
            <span class="send-place send-status">订单状态<div class="user_prov check_order_status">已发货</div></span>
            <span class="send-place send-postage">快递单号<input readonly class="user_prov order_postage_id" type="text" value="" /><button class="copy_postage_id" onclick="copy_postage_id()">复制</button></span>
            <span class="send-place">收件人<div class="user_prov user_name check_user_name"></div></span>
            <span class="send-place">手机号<div class="user_prov user_name check_user_numb"></div></span>
            <span class="send-place-info">收货地址
              <div class="edit-place-info"></div>
            </span>
            <ul class="cart_ul" >
                <li class="cart_li">
                    <ol class="cart_btn">
                        <li class="info_li"><span>商品总价</span><span class="info_sp">￥<span class="sum_of_price"></span></span></li>
                        <li class="info_li"><span>邮费</span><span class="info_sp">￥<span class="postage_price"></span></span></li>
                        <li class="info_li"><span>合计</span><span class="info_sp">￥<span class="add_price"></span></span></li>
                    </ol>
                </li>
            </ul>
        </div>
    </div>
    <div class="par_now_box">
        <div class="par_now">
            <div class="money_c"></div>
            <a onclick="checkPay()" class="go_pay"></a>
        </div>
    </div>
    <div class="tip_hide" style="display:none;"></div>
    <div class="expurgate" style="display: none;"></div>
    <div class="mask" style="display:none;"></div>
    <div class="delDiv" style="display:none">
        <div class="delDiv_tip">确认关闭？</div>
        <div class="delDiv_info">
            <span id="" class="delDiv_info_left">
                <button id="btnCancel" class="btn-green btnCancel" type="button">取消</button>
            </span>
            <span id="" class="delDiv_info_right">
                <button id="btnDelTrue" class="btn-green btnDelTrue" type="button">确认</button>
            </span>
        </div>
    </div>
</div>
</body>
<script>
/**
 * Created by Hansuku on 2018/3/7.
 */
/*滚动*/
var myscroll;
$('.check_order_status').click(function(){
    var postage_id = $(this).attr('abc');
    document.execCommand("copy");
});
function copy_postage_id(){
    var postage_id = $('.order_postage_id');
    postage_id.select();
    document.execCommand("copy");
    $('.tip_hide').html('复制成功!');
    $('.tip_hide').show().delay(800).hide(0);
}
$.ajax({
    url:"/exchange/exchange-order-list-api/"+'{{ $order_id }}',
    data:{
    },
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
    },
    type:'get',
    dataType:'json',
    success:function(data){
        if(data.result.success == true){
            $('.check_user_name').text(data.content.info.address_name);
            $('.check_user_numb').text(data.content.info.tel);
            $('.edit-place-info').text(data.content.info.address_details);
            $('.postage_price').text(data.content.info.postage);
            $('.sum_of_price').text(data.content.info.total_price);
            $('.add_price').text(parseInt(data.content.info.postage)+parseInt(data.content.info.total_price));
            var face = data.content.info.face;
            var title = data.content.info.title;
            $.each(data.content.details,function(idx,obj){
                $('.cart_li').prepend("<div class='lists'><div class='cart_pic'><img src='{{ env('CDN_DOMAIN_NAME') }}/upload/"+face+"' alt='' class='cart_img' /></div><div class='cart_info'><div class='cart_tit'><p class='cart_text'>【"+title+"】</p></div><p class='cart_style'>款号："+obj.girard+"<span class='clo-nums'>"+obj.nums+"件</span></p><p class='cart_color'>颜色："+obj.color+"</p><div class='cart_doble'><p class='cart_size'>尺码："+obj.size+"码</p><p class='cart_money'><i>￥</i>"+obj.price+"</p></div></div></div>");
            });
            myscroll = new iScroll("#wrapper",{
            });
            if(data.content.type == 0){
                //买家
                $('.money_c').text('卖家电话:'+data.content.tel);
                if(data.content.info.status == 1){
                    $('.check_order_status').text('已付款,等待卖家发货');
                    $('.go_pay').text('等待发货');
                    $('.go_pay').css('background','#ccc');
                    $('.go_pay').attr('abc',3);
                }else if(data.content.info.status == 2){
                    $('.check_order_status').text('已发货');
                    $('.go_pay').text('确认收货');
                    $('.go_pay').attr('abc',1);
                    $('.order_postage_id').val(data.content.info.express_num);
                    $('.send-postage').css('display','block');
                }else if(data.content.info.status == 3){
                    $('.check_order_status').text('已完成');
                    $('.go_pay').text('已完成');
                    $('.go_pay').css('background','#ccc');
                    $('.go_pay').attr('abc',3);
                    $('.order_postage_id').val(data.content.info.express_num);
                    $('.send-postage').css('display','block');
                }
            }else if(data.content.type == 1){
                //卖家
                if(data.content.info.status == 1){
                    $('.check_order_status').text('买家已付款,等待发货');
                    $('.go_pay').text('发货');
                    $('.go_pay').attr('abc',4);
                    $('.money_c').html("<input type='number' class='write_postage' placeholder='请输入快递单号' />");
                }else if(data.content.info.status == 2){
                    $('.check_order_status').text('已发货,等待买家收货');
                    $('.go_pay').text('等待收货');
                    $('.go_pay').css('background','#ccc');
                    $('.go_pay').attr('abc',2);
                    $('.order_postage_id').val(data.content.info.express_num);
                    $('.send-postage').css('display','block');
                }else if(data.content.info.status == 3){
                    $('.check_order_status').text('已完成');
                    $('.go_pay').text('已完成');
                    $('.go_pay').css('background','#ccc');
                    $('.go_pay').attr('abc',3);
                    $('.order_postage_id').val(data.content.info.express_num);
                    $('.send-postage').css('display','block');
                }
            }
        }
    }
});
function checkPay(){
    var status = $('.go_pay').attr('abc');
    var order_status;
    var postage_id;
    var locknum;
    if(status == 1){
        $('.delDiv').show();
        $('.mask').show();
        $('.delDiv_tip').text('是否确认收货?');
        $('#btnDelTrue').click(function(){
            locknum = 1;
            order_status = 3;
            checkLock(1);
        });
        $('#btnCancel').click(function(){
            $('.delDiv').hide();
            $('.mask').hide();
            return false;
        });
    }else if(status == 4){
        postage_id = $('.write_postage').val();
        if(postage_id.length== 0){
            $('.tip_hide').html('快递单号不能为空');
            $('.tip_hide').show().delay(800).hide(0);
            return false;
        }
        if(postage_id.length < 12){
            $('.tip_hide').html('快递单号最少12位');
            $('.tip_hide').show().delay(800).hide(0);
            return false;
        }
        order_status = 2;
        locknum = 1;
        checkLock(1);
    }else if(status == 3){
        return false;
    };
    function checkLock(checklocknum){
        if(checklocknum == 1){
            $.ajax({
                url:"/exchange/exchange-order-list-api",
                data:{
                    order_id:'{{ $order_id }}',
                    status:order_status,
                    express_num:postage_id
                },
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                },
                type:'post',
                dataType:'json',
                success:function(res){
                    if(res.result.success == true){
                        window.location.reload();
                    }else{
                        $('.tip_hide').html(res.result.errorMsg);
                        $('.tip_hide').show().delay(800).hide(0);
                    }
                }
            })
        }
    }
}
</script>
</html>
